import 'dart:collection';

import 'package:flutter/material.dart';
class DashPainter extends CustomPainter {
  Color color;
  double strokeWidth;
  DashPainter(this.color,this.strokeWidth);

  @override
  void paint(Canvas canvas, Size size) {
    var paint = Paint() // 创建一个画笔并配置其属性
      ..strokeWidth = strokeWidth // 画笔的宽度
      ..isAntiAlias = true // 是否抗锯齿
      ..color=color; // 画笔颜色

    var max =  size.width; // size获取到宽度
    var dashWidth = 5;
    var dashSpace = 5;
    double startX = 0;
    final space = (dashSpace + dashWidth);

    while (startX < max) {
      canvas.drawLine(Offset(startX, 100.0), Offset(startX + dashWidth, 100.0), paint);
      startX += space;
    }
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) => false;
}